package testweathergateway;

import java.io.*;
import java.util.Scanner;
import weather_service.weatherprovider.DefaultWeatherConfigurationBean;
import weather_service.weatherprovider.WeatherConfigurationIF;
import weather_service.weatherprovider.WeatherError;
import weather_service.weatherprovider.WeatherGateway;
import weather_service.weatherprovider.weatherdatamodel.WeatherReport;


public class TestWeatherGateway {

  public String partnerID = "1187706295";
  public String licenseKey = "f0464aaf10c38a37";
  public String zip_code;
  public String description;
  public String visibility;
  public int iconNo;
  public String location;
  public String dewpoint;
  public String feelsLikeTemp;
  public String humidity;
  public int temperature;
  public String lastUpdated;
  public String windSpeed;
  public String precipitation;
  public String misc;
 
  public void weatherInfo() {

    WeatherConfigurationIF config = new DefaultWeatherConfigurationBean(
    DefaultWeatherConfigurationBean.defaultWeatherServer, partnerID, licenseKey);
    WeatherReport weather = new WeatherReport();
    WeatherGateway gateway = new WeatherGateway(config);

    Scanner scan = new Scanner (System.in);       
    System.out.println ("Enter Zip Code:");
    System.out.println ("");        
    zip_code = scan.next();    

     
    try {
      weather = gateway.getFullForecast(zip_code, 3);
        } catch (WeatherError | IOException weatherError) {
    }
       
    String weatherString;
    String[] weatherData;
    weatherString = weather.toString();
    weatherData = weatherString.split("\n");
    
    description = weatherData[1].split("=")[1];
    visibility = weatherData[2].split("=")[1];
    iconNo = Integer.parseInt((weatherData[3].split("=")[1]).split("\r")[0]);
    location = weatherData[4].split("=")[1];
    dewpoint = weatherData[5].split("=")[1];
    feelsLikeTemp = weatherData[6].split("=")[1];
    humidity = weatherData[7].split("=")[1];
    temperature = Integer.parseInt((weatherData[8].split("=")[1]).split("\r")[0]);
    lastUpdated = weatherData[9].split("=")[1];
    windSpeed = weatherData[10].split("speed=")[1].split("]")[0];
    precipitation = weatherData[21].split("n,")[1].split(",wind")[0];
    misc = weatherData[23];
      
    System.out.println("Description: " + description);
    System.out.println("Visibility: " + visibility);
    System.out.println("Icon #: " + iconNo);
    System.out.println("Location: " + location);
    System.out.println("Dewpoint: " + dewpoint);
    System.out.println("Feels Like: " + feelsLikeTemp);
    System.out.println("Humidity: " + humidity);
    System.out.println("Temperature: " + temperature);
    System.out.println("Last Updated: " + lastUpdated);
    System.out.println("Wind Speed: " + windSpeed);
    System.out.println("Precipitation: " + precipitation);
    System.out.println("Misc: " + misc);
}
   
public static void main(String[] args) {
  TestWeatherGateway gateway = new TestWeatherGateway();
  gateway.weatherInfo();          
  }
}
